package com.jhc.drone.communication.enums;

import com.jhc.drone.communication.ws.WsDto;
import com.jhc.drone.communication.ws.WsEndpoint;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;
import java.util.stream.Stream;

@Slf4j
@Getter
public enum SystemStatusEnum {
    MAV_STATE_UNINIT((short) 0, "系统未初始化，状态未知"),
    MAV_STATE_BOOT((short) 1, "系统正在启动"),
    MAV_STATE_CALIBRATING((short) 2, "系统正在校准，尚未做好飞行准备"),
    MAV_STATE_STANDBY((short) 3, "系统已停飞并处于待命状态。可随时发射"),
    MAV_STATE_ACTIVE((short) 4, "系统已启动，可能已起飞。发动机已启动"),
    MAV_STATE_CRITICAL((short) 5, "系统处于非正常飞行模式（故障保护）。但仍可导航"),
    MAV_STATE_EMERGENCY((short) 6, "系统处于非正常飞行模式（故障保护）。它失去了对部分或整个机身的控制。它正在发出求救信号并坠毁"),
    MAV_STATE_POWEROFF((short) 7, "系统刚刚初始化其关机序列，将立即关机"),
    MAV_STATE_FLIGHT_TERMINATION((short) 8, "系统正在自行终止（故障安全或命令）");

    private final short code;

    private final String name;

    SystemStatusEnum(short code, String name) {
        this.code = code;
        this.name = name;
    }

    public static SystemStatusEnum getModel(short code) {
        return Stream.of(SystemStatusEnum.values()).filter(a -> Objects.equals(a.getCode(), code)).findFirst().orElse(null);
    }

}
